// 生成RandomHexColor
const generateRandomHexColor = function() {
  return `#${Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, '0')}`
}

// 生成随机RGBA
const generateRandomRGBA = () => {
  const r = Math.floor(Math.random() * 256)
  const g = Math.floor(Math.random() * 256)
  const b = Math.floor(Math.random() * 256)
  const a = Math.random().toFixed(2)
  return `rgba(${[ r, g, b, a ].join(',')})`
}

// 复制内容到剪贴板的两种方式1
const copyToClipboard1 = function(text) {
  navigator.clipboard && navigator.clipboard.writeText && navigator.clipboard.writeText(text)
}
// 复制内容到剪贴板的两种方式2
const copyToClipboard2 = (content) => {
  const textarea = document.createElement("textarea")
  textarea.value = content
  document.body.appendChild(textarea)
  textarea.select()
  document.execCommand("Copy")
  textarea.remove()
}


export default {
  generateRandomHexColor,
  generateRandomRGBA,
  copyToClipboard1,
  copyToClipboard2
}